package com.abc.xxx.config.security;

import com.abc.xxx.model.User;
import com.abc.xxx.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserService userService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("查询用户，username: {}", username);
        User user = userService.findUserByName(username);
        if (user == null) {
            throw new UsernameNotFoundException("找不到用户记录");
        }
        return user;
    }

}

